﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
					xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
					xmlns:local="clr-namespace:DynamicDataDisplay.Markers"
					xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0">

	<local:AngleToIsLargeArcConverter x:Key="angleToIsLargeArcConverter"/>
	<local:AngleToArcEndPointConverter x:Key="angleToEndPointConverter"/>
	<local:DonutPointConverter x:Key="donutConverter"/>
	<local:AngleRadiusToPointConverter x:Key="donutPointConverter"/>

	<!--PieChartItem Style-->
	<Style TargetType="local:PieChartItem">
		<Setter Property="BorderBrush" Value="DarkGray"/>
		<Setter Property="StrokeThickness" Value="1"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="local:PieChartItem">
					<Path Stretch="Fill" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}"
						  StrokeThickness="{TemplateBinding StrokeThickness}">
						<Path.Data>
							<PathGeometry>
								<PathFigure StartPoint="0,1" IsClosed="True" IsFilled="True">
									<LineSegment Point="1,1"/>
									<ArcSegment IsLargeArc="{d3:TemplateBinding AngleInChart, Converter={StaticResource angleToIsLargeArcConverter}}" 
												RotationAngle="{TemplateBinding AngleInChart}" 
												Point="{d3:TemplateBinding AngleInChart, Converter={StaticResource angleToEndPointConverter}}" 
												Size="1,1"/>
									<LineSegment Point="0,1"/>
								</PathFigure>
							</PathGeometry>
						</Path.Data>
					</Path>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
		<Setter Property="local:PiePanel.ArcWidth" Value="{d3:SelfBinding Angle}"/>
	</Style>

	<!--donutPieChartItemStyle-->
	<Style TargetType="local:PieChartItem" BasedOn="{StaticResource {x:Type local:PieChartItem}}" x:Key="donutPieChartItemStyle">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="local:PieChartItem">
					<Path Stretch="Fill" Fill="{TemplateBinding Background}" Stroke="{x:Null}"
						  StrokeThickness="0">
						<Path.Data>
							<CombinedGeometry GeometryCombineMode="Exclude">
								<CombinedGeometry.Geometry1>
									<PathGeometry>
										<PathFigure StartPoint="0,1" IsClosed="True" IsFilled="True">
											<LineSegment Point="1,1"/>
											<ArcSegment IsLargeArc="{d3:TemplateBinding AngleInChart, Converter={StaticResource angleToIsLargeArcConverter}}" 
												RotationAngle="{TemplateBinding AngleInChart}" 
												Point="{d3:TemplateBinding AngleInChart, Converter={StaticResource angleToEndPointConverter}}" 
												Size="1,1"/>
											<LineSegment Point="0,1"/>
										</PathFigure>
									</PathGeometry>
								</CombinedGeometry.Geometry1>
								<CombinedGeometry.Geometry2>
									<PathGeometry>
										<PathGeometry.Transform>
											<ScaleTransform ScaleX="0.5" ScaleY="0.5" CenterX="0" CenterY="0.99999"/>
										</PathGeometry.Transform>
										<PathFigure StartPoint="0,1" IsClosed="True" IsFilled="True">
											<LineSegment Point="1,1"/>
											<ArcSegment IsLargeArc="{d3:TemplateBinding AngleInChart, Converter={StaticResource angleToIsLargeArcConverter}}" 
														RotationAngle="{TemplateBinding AngleInChart}" 
														Point="{d3:TemplateBinding AngleInChart, Converter={StaticResource angleToEndPointConverter}}" 
														Size="1,1"/>
											<LineSegment Point="0,1"/>
										</PathFigure>
									</PathGeometry>
								</CombinedGeometry.Geometry2>
							</CombinedGeometry>
						</Path.Data>
					</Path>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<!--previous attempt to create a donut chart-->
	<!--<PathFigure StartPoint="{d3:TemplateBinding RadiusStartRatio, Converter={StaticResource donutConverter}, ConverterParameter=start}" 
											IsClosed="True" IsFilled="True">

		<LineSegment Point="1,1"/>

		<ArcSegment IsLargeArc="{d3:TemplateBinding AngleInChart, Converter={StaticResource angleToIsLargeArcConverter}}" 
												RotationAngle="{TemplateBinding AngleInChart}" 
												Size="1,1">
			<ArcSegment.Point>
				<MultiBinding Converter="{StaticResource donutPointConverter}" ConverterParameter="end">
					<d3:TemplateBinding Path="RadiusStartRatio"/>
					<d3:TemplateBinding Path="AngleInChart"/>
				</MultiBinding>
			</ArcSegment.Point>
		</ArcSegment>

		<LineSegment>
			<LineSegment.Point>
				<MultiBinding Converter="{StaticResource donutPointConverter}" ConverterParameter="startInner">
					<d3:TemplateBinding Path="RadiusStartRatio"/>
					<d3:TemplateBinding Path="AngleInChart"/>
				</MultiBinding>
			</LineSegment.Point>
		</LineSegment>

		<ArcSegment IsLargeArc="{d3:TemplateBinding AngleInChart, Converter={StaticResource angleToIsLargeArcConverter}}" 
												RotationAngle="{d3:TemplateBinding AngleInChart}" 
												SweepDirection="Clockwise"
												Size="{d3:TemplateBinding RadiusStartRatio, Converter={StaticResource donutConverter}}">
			<ArcSegment.Point>
				<MultiBinding Converter="{StaticResource donutPointConverter}" ConverterParameter="endInner">
					<d3:TemplateBinding Path="RadiusStartRatio"/>
					<d3:TemplateBinding Path="AngleInChart"/>
				</MultiBinding>
			</ArcSegment.Point>
		</ArcSegment>
	</PathFigure>-->

	<!--Pie Chart Style-->
	<Style TargetType="{x:Type local:PieChart}">
		<Style.Resources>
			<Style TargetType="local:TemplateMarkerGenerator">
				<Setter Property="MarkerTemplate">
					<Setter.Value>
						<DataTemplate>
							<local:PieChartItem/>
						</DataTemplate>
					</Setter.Value>
				</Setter>
			</Style>
		</Style.Resources>

		<Setter Property="ItemsPanel">
			<Setter.Value>
				<ItemsPanelTemplate>
					<local:PiePanel StartAngle="{Binding Path=(local:PieChart.StartAngle), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:PieChart}}}"/>
				</ItemsPanelTemplate>
			</Setter.Value>
		</Setter>

		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="ContentControl">
					<Grid Background="{TemplateBinding Background}">
						<ContentPresenter Content="{TemplateBinding Content}"/>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<!--PieChartLegendItem-->
	<Style TargetType="{x:Type local:PieChartLegendItem}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:PieChartLegendItem}">
					<StackPanel Orientation="Horizontal" Margin="2">
						<Grid VerticalAlignment="Stretch" HorizontalAlignment="Left" Margin="0,0,5,0">
							<Path Fill="{TemplateBinding Background}" Stroke="LightGray" Stretch="Uniform" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="20">
								<Path.Data>
									<PathGeometry>
										<PathFigure StartPoint="0,1" IsClosed="True" IsFilled="True">
											<LineSegment Point="1,1"/>
											<ArcSegment IsLargeArc="False" RotationAngle="30" Point="0.866,0.5" Size="1,1"/>
											<LineSegment Point="0,1"/>
										</PathFigure>
									</PathGeometry>
								</Path.Data>
							</Path>
						</Grid>
						<TextBlock Text="{TemplateBinding d3:Legend.Description}"/>
					</StackPanel>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>